package com.cskaoyan.service.wx;

import com.cskaoyan.bean.MarketFeedback;
import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import com.cskaoyan.mapper.MarketUserMapper;
import com.cskaoyan.model.vx.bo.WxFeedbackBo;
import jdk.internal.instrumentation.TypeMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * @author hanshuai
 * @version 1.0
 * @description @TODO
 * @date 2021/12/2 22:46
 */
@Service
public class WxFeedbackServiceImpl implements WxFeedbackService{
    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;
    @Autowired
    MarketUserMapper marketUserMapper;
    @Override
    public void feedbackSubmit(WxFeedbackBo wxFeedbackBo, HttpSession httpSession) {
        MarketFeedback marketFeedback = new MarketFeedback();
        Date date = new Date();
        marketFeedback.setAddTime(date);
        marketFeedback.setContent(wxFeedbackBo.getContent());
        marketFeedback.setDeleted(false);
        marketFeedback.setId(null);
        marketFeedback.setHasPicture(wxFeedbackBo.getHasPicture());
        String[] picUrls = wxFeedbackBo.getPicUrls();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        for (String picUrl : picUrls) {
            stringBuilder.append(picUrl+",");
        }
        stringBuilder.deleteCharAt(stringBuilder.length()-1);
        stringBuilder.append("]");
        marketFeedback.setPicUrls(stringBuilder.toString());
        marketFeedback.setStatus(1);
        marketFeedback.setFeedType(wxFeedbackBo.getFeedType());
        marketFeedback.setMobile(wxFeedbackBo.getMobile());
        marketFeedback.setUserId((Integer) httpSession.getAttribute("wxUserId"));
        MarketUser wxUser = marketUserMapper.selectByPrimaryKey((Integer) httpSession.getAttribute("wxUserId"));
        marketFeedback.setUsername(wxUser.getUsername());
        marketFeedback.setUpdateTime(date);
        marketFeedbackMapper.insertSelective(marketFeedback);
    }
}
